{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXkAAAEKCAYAAAD3tSVSAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3X2UHHWd7/H3Nzz4ACQIKNwEEnKHy7MKroaorPTIomFV\nou51BXtwI17heABB4S5cTTKdO7qCGw8oXFfiRVHBjZzVhagLCwrNkwRReRBMCGQeDAS5AkIYwDUL\n3/tH1UwqPd3T1d1V3dXVn9c5faarq7r61zXV3/rV9/erX5m7IyIi+TSj0wUQEZH0KMiLiOSYgryI\nSI4pyIuI5JiCvIhIjinIi4jkmIJ8DzKzj5jZ9Smu/zkz27/FdXzLzP53jXn/ZGafa3H9/8vMVk0z\n/+/M7LZWPiNrzOxoM1vX6XJIeynI51T4g77DzJ4xsyfN7DYz+wsAd/+euy9K67PdfTd3H01x/Z90\n9y+0uI4vuvupAGY2z8xeNrPK30Psi0jM7HQzu9vM/mRm36wy/1gzW2dm42b2MzObWzH/wvD/9Acz\nu6CpL1WHu9/u7ofEWdbMjjGzTWmUQ9pLQT6HzGw34EfAV4DXAHOAFcB/JLDuPO4zRhDQrYV1PAYM\nAZdPWbnZnsAPgM8BewC/Ar4fmX8acALweuANwPvM7NQWypKEiW0iXS6PP1iBAwF396s98B/u/lN3\nfwCmpiLM7GAzu8HMngprmx+KzPuWmX3NzH5iZs8BhfC1fwrfs8XMbo7WTMNa8X+NvP9SM/txuOyd\nZjY/suxFZvaEmT1rZveZ2aGVX8bMdjOzm8zs4sg6a6VyRs3syPB5MSzLIeH0KWb2w/D5oJl9J3zb\nLeHfZ8IyHrVtdfaPZva0mW00s5pnP+5+jbuvAZ6uMvuDwAPu/kN3/zNQAt5oZgeG8z8KfNndH3f3\nx4GVwJIa32/irOMTZvZY+DgnMn9nM7s4fP3RcPvuFM7brnZuZiNmdk643f9oZq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DfCuFFBGR5tQN8u7+kpmdAdxA0NPmcndfZ2anBbN9lbv/m5n9tZk9QnCe8rF0iy0i\nInHUTdeIiEj3SqUlwMwWmdl6M9tgZufVWOarZvawmd1rZkekUY68qLc9zewYM3vGzH4dPpZ2opzd\nwMwuN7MnzOz+aZbRvhlDvW2p/bIxZravmd1kZg+a2W/M7FM1lmts/2y2W06tBwlePKVH7O15DLCm\n02XthgdwNHAEcH+N+do3k9uW2i8b2577EI4WAOwKPJRE7EyjJr8AeNjdx9x9K7AaWFyxzGLgOwDu\nfhcwy8z2TqEseRBnewKoUTsGd78d+OM0i2jfjCnGtgTtl7G5++/d/d7w+TjBRaVzKhZreP9MI8jP\nATZFph9lakErl3msyjISiLM9Ad4anr79xMwObU/Rckn7ZrK0XzbBzPYnOEu6q2JWw/tnzw01nFO/\nAua6+wtmdjxwDXBgh8skov2yCWa2K/AvwFlhjb4ladTkHwPmRqb3DV+rXGa/OstIoO72dPdxd38h\nfH4dsJOZ7dG+IuaK9s2EaL9snJntSBDgv+vu11ZZpOH9M40gP3nxlJntTHDx1JqKZdYAH4XJK2qr\nXjwlQIztGc3JmdkCgq6xT7e3mF3FqJ0r1r7ZmJrbUvtlU74J/Nbdv1JjfsP7Z+LpGtfFU4mKsz2B\n/25mnwS2Ai8CH+5cibPNzL4HFIA9zex3BLe62hntmw2rty3RftkQM3s7UAR+Y2b3AA58lqBnXdP7\npy6GEhHJsewMdygiIolTkBcRyTEFeRGRHFOQFxHJMQV5EZEcU5AXEckxBXkRkRxTkBcRybH/D3et\n+KHgvuHhAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x10cfa6780>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "%matplotlib inline\n",
    "\n",
    "from ipywidgets import interact\n",
    "import ipywidgets as widgets\n",
    "\n",
    "# Interactive version of drawing the Sierpinski triangle\n",
    "# Doing Math with Python (Chapter 6)\n",
    "\n",
    "'''\n",
    "sierpinski.py\n",
    "\n",
    "Draw Sierpinski Triangle\n",
    "'''\n",
    "import random\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "def transformation_1(p):\n",
    "    x = p[0]\n",
    "    y = p[1]\n",
    "    x1 = 0.5*x\n",
    "    y1 = 0.5*y\n",
    "    return x1, y1\n",
    "\n",
    "def transformation_2(p):\n",
    "    x = p[0]\n",
    "    y = p[1]\n",
    "    x1 = 0.5*x + 0.5\n",
    "    y1 = 0.5*y + 0.5\n",
    "    return x1, y1\n",
    "\n",
    "def transformation_3(p):\n",
    "    x = p[0]\n",
    "    y = p[1]\n",
    "    x1 = 0.5*x + 1\n",
    "    y1 = 0.5*y\n",
    "    return x1, y1\n",
    "\n",
    "def get_index(probability):\n",
    "    r = random.random()\n",
    "    c_probability = 0\n",
    "    sum_probability = []\n",
    "    for p in probability:\n",
    "        c_probability += p\n",
    "        sum_probability.append(c_probability)\n",
    "    for item, sp in enumerate(sum_probability):\n",
    "        if r <= sp:\n",
    "            return item\n",
    "    return len(probability)-1\n",
    "\n",
    "def transform(p):\n",
    "    # list of transformation functions\n",
    "    transformations = [transformation_1, transformation_2, transformation_3]\n",
    "    probability = [1/3, 1/3, 1/3]\n",
    "    # pick a random transformation function and call it\n",
    "    tindex = get_index(probability)\n",
    "    t = transformations[tindex]\n",
    "    x, y = t(p)\n",
    "    return x, y\n",
    "\n",
    "def draw_sierpinski(n):\n",
    "    # We start with (0, 0)\n",
    "    x = [0]\n",
    "    y = [0]\n",
    "\n",
    "    x1, y1 = 0, 0\n",
    "    for i in range(n):\n",
    "       x1, y1 = transform((x1, y1))\n",
    "       x.append(x1)\n",
    "       y.append(y1)  \n",
    "    \n",
    "    plt.plot(x, y, 'o')\n",
    "    plt.title('Sierpinski with {0} points'.format(n))\n",
    "    plt.show()\n",
    "\n",
    "i = interact(draw_sierpinski, n=widgets.IntSlider(min=100, max=10000, step=1, value=10))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
